class_name XPTracker
extends VBoxContainer

# ===============================================

@export var player_stats: PlayerStats

# ===============================================

@onready var progress_bar: ProgressBar = $ProgressBar
@onready var xp_label: Label = $MarginContainer/HBoxContainer/XPLabel
@onready var level_label: Label = $MarginContainer/HBoxContainer/LevelLabel

# ===============================================

func __on_player_stats_changed() -> void:
	if player_stats.level < PlayerStats.MAX_LEVEL:
		var xp_requirement: int = player_stats.get_current_xp_requirement()
		xp_label.text = "%s/%s" % [player_stats.xp, xp_requirement]
		progress_bar.value = (player_stats.xp as float / xp_requirement) * 100
	else:
		xp_label.text = "MAX"
		progress_bar.value = 100
	level_label.text = "lv: %s" % player_stats.level

# ===============================================

func _ready() -> void:
	player_stats.changed.connect(__on_player_stats_changed)
	__on_player_stats_changed()
